package com.lei.controller;

import com.lei.domain.Role;
import com.lei.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @ClassName RoleController
 * @Description TODO
 * @Author Admin
 * @Date 2021/9/15 9:42
 * @Version 1.0
 */
@RequestMapping("/role")
@Controller
public class RoleController {
    @Autowired
    private RoleService roleService;
    @RequestMapping("/list")
    public ModelAndView list(){
        //初始化ModeAndView
        ModelAndView modelAndView=new ModelAndView();
       List<Role> roleList= roleService.list();
        //设置模型.
        modelAndView.addObject("roleList",roleList);
        //设置视图
        modelAndView.setViewName("role-list");
        System.out.println(roleList);
        return modelAndView;

    }
    @RequestMapping("/save")
    public String save(Role role){
        roleService.save(role);
        return "redirect:/role/list";
    }

    @RequestMapping("/del/{roleId}")
    public String del(@PathVariable("roleId") Long roleId){
        roleService.del(roleId);
        return "redirect:/role/list";

    }
}
